package com.big.patient.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.big.common.utils.UUIDGenerator;
import com.big.model.model.patient.PatientDsn;
import com.big.model.model.patient.PatientInfo;
import com.big.model.vo.patient.PatientVo;
import com.big.patient.mapper.PatientMapper;
import com.big.patient.service.PatientDsnService;
import com.big.patient.service.PatientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Slf4j
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, PatientInfo> implements PatientService {

    @Autowired
    PatientDsnService patientService;

    //添加用户
    @Override
    public void savePatient(PatientVo patientVo) {
        PatientInfo patientInfo = new PatientInfo();
        //编号
        patientInfo.setUserId(patientVo.getUserId());
        patientInfo.setPhone(patientVo.getPhone());
        patientInfo.setAvatar(patientVo.getAvatar());
        patientInfo.setName(patientVo.getPhone());
        baseMapper.insert(patientInfo);
        //加入密
        PatientDsn patientDsn=new PatientDsn();
        patientDsn.setUId(patientVo.getUserId());
        patientDsn.setPhone(patientVo.getPhone());
        patientDsn.setPassword(patientVo.getPassword());
        patientService.save(patientDsn);
    }

    @Override
    public PatientInfo findUserInfo(String phone) {
        QueryWrapper<PatientInfo> wrapper=new QueryWrapper<>();
        if(!StringUtils.isEmpty(phone)){
            wrapper.eq("phone",phone);
        }
        PatientInfo patientInfo = baseMapper.selectOne(wrapper);
        return patientInfo;
    }

    @Override
    public PatientInfo findUserInfoById(String uid) {
        QueryWrapper<PatientInfo> wrapper=new QueryWrapper<>();
        if(!StringUtils.isEmpty(uid)){
            wrapper.eq("user_id",uid);
        }
        PatientInfo patientInfo = baseMapper.selectOne(wrapper);
        return patientInfo;
    }



}
